package com.example.concurrent.AtomicBoolean;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by SOAL on 2017/2/11 0011.
 */
public class AtomicBooleandemo {

    public static void main(String[] args) {
        AtomicBoolean atomicBoolean0 = new AtomicBoolean();

        AtomicBoolean atomicBoolean = new AtomicBoolean(true);

        boolean value = atomicBoolean.get();
        System.out.println(value);

//        atomicBoolean.set(false);
//        System.out.println(atomicBoolean.get());

//        boolean oldValue = atomicBoolean.getAndSet(false);
//        System.out.println(oldValue);
//        System.out.println(atomicBoolean.get());

        boolean expectedValue = true;
        boolean newValue      = false;

        boolean wasNewValueSet = atomicBoolean.compareAndSet(
                expectedValue, newValue);

        System.out.println(wasNewValueSet);
        System.out.println(atomicBoolean.get());

    }
}
